# demo5 ------------输入与输出(上)
# %方式
name = "Mike"
name2 = "'wife"
age = 10
print("%s age is %d-years-old" % (name + name2, age + 1))

# format()函数
# 1.顺序填充
str1 = "{} age is {}-years-old".format(name + name2, age + 1, "多余的也没事,不会填充进去")
print(str1)
# 2.索引填充
str2 = "{0},{1},{0}!".format("hello", "world")
print(str2)
# 3.关键字填充
str3 = "{name} age is {age}".format(age=10, name="Mike")
print(str3)
# 4.通过字典设置参数, **展开map集合
info = {"name": "Mike", "age": 10}
str4 = "NAME: {name}, AGE: {age}".format(**info)
print(str4)
# 5.利用列表的索引设置参数
list1 = ["Mike", "Amy"]
str5 = "{0[0]}'wife {0[1]} is {1} years old".format(list1, 11)
print(str5)

# format格式化输出
print("圆周率: {:+.2f}".format(3.141592653769))
print("{:,}".format(1000000000))
print("{:.3e}".format(102000000))
print("{:.2%}".format(0.25))
# 更多类型: https://www.runoob.com/python/att-string-format.html


# 字符串格式化输出
name1 = "Mike"
print("{:*<10}".format(name1))  # 使用*字符 向左填充< 占位10个字符
print("{:>10}".format(name1))  # 使用 字符 向右填充> 占位10个字符
print("{:#^10}".format(name1))  # 居中填充^

# demo6 ------------输入与输出(下)
# f-string
name = "Mike"
age = 3
print(f"{name}今年{age}岁了")

# 格式化输出
str1 = "world"
print(f"{str1:*<10}")
print(f"{str1:>10}")
print(f"{str1:#^10}")

# 在{}中可以进行计算/函数调用
print(f"{2 * 100}")
print(f"{'abc'.upper()}")

# 多行f-string
teacher = "Ms.Li"
days = 3
message = (f"{'请假条':_^15}\n"
           f"{teacher}您好：\n"
           f"我想请假{days}天，望批准！"
           )
print(message)

print(f"{{86}}")

# 使用空格隔开
print("aaa", "bbb", "ccc", 200)
print("hello", "world", "python", sep=',,')
print("hello", end="")
print("world", end="\t")
print("python", end='\n')
print("end")

# 输入
password = input("请输入密码：")
print("密码：", password)

a = input("输入一个数字：")
print(type(a))
print(type(int(a)))
# 无论输入输入纯数字还是字符串，最后都会识别为str类型

b = "abc:" + str(100)
print(type(str(100)))

# 也可以直接转换
c = int(input("输入数字："))
print(c + 100)
